﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJP.ComponentModel;

namespace WJP
{
    /// <summary>
    /// 领域应用程序（用于启动领域实体框架）
    /// </summary>
    public class DomainApp : AppBase
    {
        private DomainApp(Action<AppOptions> option = null)
            : base(option)
        {

        }

        /// <summary>
        /// 创建DomainApp
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        public static DomainApp Create(Action<AppOptions> option = null)
        {
            return new DomainApp(option);
        }

        /// <summary>
        /// 启动领域应用程序
        /// </summary>
        public void Startup()
        {
            try
            {
                StartupApplication();
            }
            catch (Exception ex)
            {
                throw new AppException("领域应用程序在启动时发生异常", ex);
            }
        }

        /// <summary>
        /// 当外部程序在完全退出时，通过领域应用程序也同时退出
        /// </summary>
        public void NotifyExit()
        {
            try
            {
                OnExit();
            }
            catch (Exception ex)
            {
                throw new AppException("领域应用程序在退出时发生异常", ex);
            }
        }
    }
}
